package com.hzncc.flowable_diboot.custom_field.vo;

import com.diboot.core.binding.annotation.BindEntity;
import com.diboot.core.binding.annotation.BindEntityList;
import com.diboot.core.util.S;
import com.hzncc.flowable_diboot.custom_field.entity.CustomTableItemConfig;
import com.hzncc.flowable_diboot.custom_field.entity.FilterSetting;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* 自定义表格配置 VO定义
* @author MyName
* @version 1.0
* @date 2024-11-14
* Copyright © MyCorp
*/
@Getter @Setter @Accessors(chain = true)
public class CustomTableConfigDetailVO extends CustomTableConfigListVO  {
private static final long serialVersionUID = 1576145361855658684L;

    @BindEntityList(
            entity = CustomTableItemConfig.class,
            condition = "this.id=custom_table_config_id",
            orderBy = "sort",
            deepBind = true
    )
    private List<CustomTableItemConfigListVO> tableItemConfigs;


    @BindEntityList(
            entity = FilterSetting.class,
            condition = "this.id=custom_table_config_id",
            deepBind = true
    )
    private List<FilterSettingListVO> filterSettings;

    public Map<String,String> getConditionMap(){
        if (filterSettings != null){
            return filterSettings.stream().collect(Collectors.toMap(FilterSetting::getFieldName, FilterSetting::getCondition));
        }else {
            return null;
        }
    }

    public Set<String> flagFiled(){
        if (filterSettings!= null){
            return filterSettings.stream().filter(e -> S.equals(e.getRangeFlag(),"1")).map(FilterSetting::getFieldName).collect(Collectors.toSet());
        }else {
            return null;
        }
    }
}